import type { SysUser } from '@nbase/db';
import type { IPaginationResponse, IUser } from '@nbase/shared';

/**
 * SysUser -> IUser 映射（对外返回使用）
 */
export function toUser(user: SysUser): IUser {
  return {
    id: user.id,
    username: user.username,
    nickname: user.nickname,
    email: user.email,
    mobile: user.mobile,
    avatar: user.avatar,
    status: user.status,
    deptId: user.deptId,
    description: user.description,
    createdAt: user.createdAt?.toISOString(),
    updatedAt: user.updatedAt?.toISOString(),
  };
}

/**
 * 分页结果 SysUser -> IUser
 */
export function toUserPage(page: IPaginationResponse<SysUser>): IPaginationResponse<IUser> {
  return {
    ...page,
    items: page.items.map(toUser),
  };
}

